home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 3 of 3.iso / chapte11 / getdata / phone.c < prev    next >
C/C++ Source or Header  |  1996-04-28  |  22KB  |  653 lines

  1. #include <windows.h> 
  2. #include <windowsx.h> 
  3. #include "phone.h" 
  4. #include "tapi.h"
  5.  
  6. #define BUFSIZE 256
  7. #define APIHIVERSION     0x00010028    /* 1.40 */
  8. #define APILOWVERSION    0x00010000    /* 1.0 */
  9. #define EXTHIVERSION     0x00010005    /* 1.5 */
  10. #define EXTLOWVERSION    0x00000009    /* 0.9 */ 
  11. #define MAX_PHONE        2
  12. #define OWNER            0
  13. #define MONITOR        1
  14.  
  15. LPCTSTR lpszAppName = "phoneGetData";
  16. LPCTSTR lpszTitle   = "phoneGetData"; 
  17.  
  18.  
  19. #if defined (WIN32)
  20.     #define IS_WIN32 TRUE
  21. #else
  22.     #define IS_WIN32 FALSE
  23. #endif
  24.  
  25. #define IS_NT      IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
  26. #define IS_WIN32S  IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
  27. #define IS_WIN95   (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32
  28.  
  29. HINSTANCE hInst;   // current instance
  30. HWND hWnd;         // parent window handle
  31. HWND hListWnd;     // listbox
  32. HDC  hdc;
  33. TEXTMETRIC  tm ;
  34.  
  35. BOOL RegisterWin95( CONST WNDCLASS* lpwc );
  36.  
  37.  
  38. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  39.                       LPTSTR lpCmdLine, int nCmdShow)
  40. {
  41.    MSG      msg;
  42.    WNDCLASS wc;
  43.  
  44.    wc.style         = CS_HREDRAW | CS_VREDRAW;
  45.    wc.lpfnWndProc   = (WNDPROC)WndProc;       
  46.    wc.cbClsExtra    = 0;                      
  47.    wc.cbWndExtra    = 0;                      
  48.    wc.hInstance     = hInstance;              
  49.    wc.hIcon         = LoadIcon (hInstance, lpszAppName); 
  50.    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  51.    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  52.    wc.lpszMenuName  = lpszAppName;              
  53.    wc.lpszClassName = lpszAppName;              
  54.  
  55.    if ( IS_WIN95 )
  56.    {
  57.       if ( !RegisterWin95( &wc ) )
  58.          return( FALSE );
  59.    }
  60.    else if ( !RegisterClass( &wc ) )
  61.       return( FALSE );
  62.  
  63.    hInst = hInstance; 
  64.  
  65.    hWnd = CreateWindow( lpszAppName, 
  66.                         lpszTitle,    
  67.                         WS_OVERLAPPEDWINDOW, 
  68.                         CW_USEDEFAULT, 0, 
  69.                         CW_USEDEFAULT, 0,  
  70.                         NULL,              
  71.                         NULL,              
  72.                         hInstance,         
  73.                         NULL               
  74.                       );
  75.  
  76.    if ( !hWnd ) 
  77.       return( FALSE );
  78.  
  79.    ShowWindow( hWnd, nCmdShow ); 
  80.    UpdateWindow( hWnd );         
  81.  
  82.    while( GetMessage( &msg, NULL, 0, 0) )   
  83.    {
  84.       TranslateMessage( &msg ); 
  85.       DispatchMessage( &msg );  
  86.    }
  87.  
  88.    return( msg.wParam ); 
  89. }
  90.  
  91.  
  92. BOOL RegisterWin95( CONST WNDCLASS* lpwc )
  93. {
  94.     WNDCLASSEX wcex;
  95.  
  96.    wcex.style         = lpwc->style;
  97.    wcex.lpfnWndProc   = lpwc->lpfnWndProc;
  98.    wcex.cbClsExtra    = lpwc->cbClsExtra;
  99.    wcex.cbWndExtra    = lpwc->cbWndExtra;
  100.    wcex.hInstance     = lpwc->hInstance;
  101.    wcex.hIcon         = lpwc->hIcon;
  102.    wcex.hCursor       = lpwc->hCursor;
  103.    wcex.hbrBackground = lpwc->hbrBackground;
  104.    wcex.lpszMenuName  = lpwc->lpszMenuName;
  105.    wcex.lpszClassName = lpwc->lpszClassName;
  106.  
  107.    // Added elements for Windows 95.
  108.    //...............................
  109.    wcex.cbSize = sizeof(WNDCLASSEX);
  110.    wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName, 
  111.                             IMAGE_ICON, 16, 16,
  112.                             LR_DEFAULTCOLOR );
  113.             
  114.    return RegisterClassEx( &wcex );
  115. }
  116.  
  117. typedef struct tagMYINFO    // general application information
  118. {
  119.     HPHONEAPP phoneApp;      // instance handle TAPI gives back to us                                                                              through phoneInitialize()
  120.     DWORD dwNumDevices;     // number of available devices
  121.     DWORD dwAPIVersion;     // API version the phone supports
  122.     DWORD dwExtVersion;        // extended version
  123. } MYINFO;
  124.  
  125. typedef struct tagPHONEINFO  // information on an open phone
  126. {
  127.    HPHONE     hPhone;           // handle to the phone as returned by phoneOpen 
  128.     DWORD      dwDeviceID;            // device ID of the phone device
  129.     DWORD        dwRequestID;
  130.     char       szPhoneName[128]; // the phone's name 
  131. }PHONEINFO;
  132.  
  133. MYINFO myInfo;          //instance of MYINFO structure
  134. PHONEINFO myPhoneInfo[MAX_PHONE];  //instance of myPhoneInfo structure
  135.  
  136. LONG lRet;        //return code
  137. char buf[BUFSIZE];    // buffer for debug message
  138. char DataBuf[BUFSIZE]; //get/set data buffer;
  139.  
  140. DWORD i;
  141. DWORD dwHookSwitchDevs;
  142. DWORD dwLampMode;
  143. DWORD dwRingMode;
  144. DWORD dwRingVolume;
  145. DWORD dwHookSwitchVolume;
  146. DWORD dwPhoneStates;
  147. DWORD dwButtonModes;
  148. DWORD dwButtonStates;
  149. DWORD dwGain;
  150. HICON hIcon;
  151.  
  152. LONG lRet;
  153. char buf[BUFSIZE];
  154.  
  155. PHONECAPS*             pPhoneCaps;
  156. PHONEBUTTONINFO*  pButtonInfo;
  157. VARSTRING*            pVarString;
  158. PHONESTATUS*        pPhoneStatus;
  159. PHONEEXTENSIONID    ext_id;                                             
  160.  
  161.  
  162. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  163. {
  164.    switch( uMsg )
  165.    {
  166.       case WM_COMMAND :
  167.          switch( LOWORD( wParam ) )
  168.          {
  169.             case IDM_RUN  :
  170.                     pPhoneCaps = (PHONECAPS *) calloc (1, sizeof(PHONECAPS)+1000);
  171.                     pPhoneCaps->dwTotalSize = sizeof(PHONECAPS) + 1000;
  172.                    phoneGetDevCaps(myInfo.phoneApp, OWNER, myInfo.dwAPIVersion, myInfo.dwExtVersion, 
  173.                                         pPhoneCaps);
  174.                
  175.                 if (pPhoneCaps->dwNumSetData > 0)
  176.                     {
  177.                 
  178.                         wsprintf( DataBuf, "This is test information");
  179.                         lRet = phoneSetData(myPhoneInfo[OWNER].hPhone, pPhoneCaps->dwNumSetData, &DataBuf, sizeof(buf));
  180.                         if (lRet > 0)
  181.                       {
  182.                        myPhoneInfo[OWNER].dwRequestID = lRet;
  183.                       wsprintf(buf, "phoneSetData proceeding!");
  184.                             SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  185.                       }
  186.                          else 
  187.                       {
  188.                             wsprintf( buf,"phoneSetData failed, err=x%lx", lRet);
  189.                           phoneError(lRet);
  190.                             SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  191.                       }    
  192.                     }
  193.                     else
  194.                     {
  195.                         wsprintf( buf,"The phone device does not support the download capability.");
  196.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  197.                       phoneError(lRet);
  198.                         break;
  199.                     }
  200.                     if (pPhoneCaps->dwNumGetData > 0)
  201.                     {                
  202.                         lRet = phoneGetData(myPhoneInfo[OWNER].hPhone,pPhoneCaps->dwNumGetData, DataBuf, sizeof(DataBuf));
  203.                         if (lRet == 0)
  204.                       {
  205.                        wsprintf(buf, "phoneGetData succeeded!");
  206.                            SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  207.                             SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) DataBuf) ;
  208.                       }
  209.                          else 
  210.                       {
  211.                             wsprintf( buf,"phoneGetData failed, err=x%lx", lRet);
  212.                           phoneError(lRet);
  213.                       }    
  214.                     }
  215.                     else
  216.                     {
  217.                         wsprintf( buf,"The phone device does not support the upload capability.");
  218.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  219.                       phoneError(lRet);
  220.                         break;
  221.                     }
  222.                     free(pPhoneCaps);
  223.                     break;
  224.                    
  225.             case IDM_EXIT :
  226.                for (i = 0; i < myInfo.dwNumDevices; i++)
  227.                     phoneClose(myPhoneInfo[i].hPhone);
  228.                 
  229.                    phoneShutdown(myInfo.phoneApp);
  230.                DestroyWindow( hWnd );
  231.                break;
  232.  
  233.              case IDM_ABOUT :
  234.                DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About );
  235.                break;         
  236.          }
  237.                 
  238.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  239.  
  240.       
  241.        case WM_CREATE :
  242.  
  243.           hdc = GetDC (hWnd) ;
  244.           GetTextMetrics (hdc, &tm) ;
  245.           ReleaseDC (hWnd, hdc) ;
  246.  
  247.           hListWnd = CreateWindowEx( 0, "listbox", 
  248.                         " ",    
  249.                         WS_CHILD | WS_VISIBLE,  
  250.                         tm.tmAveCharWidth, tm.tmHeight * 3, 
  251.                         tm.tmAveCharWidth * 16 +
  252.                                    GetSystemMetrics (SM_CXVSCROLL), 
  253.                         tm.tmHeight * 5,  
  254.                         hWnd,              
  255.                         NULL,              
  256.                         hInst,         
  257.                         NULL               
  258.                         );
  259.       
  260.              //phoneInitialize
  261.                //...............................................
  262.             lRet = phoneInitialize(&myInfo.phoneApp, hInst, phoneCallback, lpszAppName, &myInfo.dwNumDevices);
  263.             if (lRet == 0) 
  264.             {
  265.                 
  266.                wsprintf(buf, "phoneInitialize succeeded!");
  267.                    SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  268.             }
  269.                
  270.                else 
  271.                {
  272.                    wsprintf( buf,"phoneInitialize failed, err=x%lx",lRet);
  273.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  274.                     phoneError(lRet);
  275.                     break;
  276.             }                    
  277.                
  278.             //phoneNegotiateAPIVersion
  279.                   //...............................................
  280.             lRet = phoneNegotiateAPIVersion(myInfo.phoneApp, 0, APILOWVERSION, APIHIVERSION, 
  281.                                                     &myInfo.dwAPIVersion, &ext_id);
  282.             if (lRet == 0)                        
  283.             {
  284.                wsprintf(buf, "phoneNegotiateAPIVersion succeeded!");
  285.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  286.             }
  287.                   else 
  288.                   {
  289.                    wsprintf(buf, "phoneNegotiateAPIVersion failed, err=x%lx", lRet);
  290.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  291.                     phoneError(lRet);
  292.                     phoneShutdown(myInfo.phoneApp);
  293.                break;
  294.              }
  295.  
  296.                //phoneNegotiateExtVersion
  297.                //...............................................
  298.             lRet = phoneNegotiateExtVersion(myInfo.phoneApp, 0, myInfo.dwAPIVersion, EXTLOWVERSION, 
  299.                                                 EXTHIVERSION, &myInfo.dwExtVersion);
  300.             if (lRet == 0)                        
  301.             {
  302.                     wsprintf(buf, "phoneNegotiateExtVersion succeeded!");
  303.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  304.               }
  305.                   else 
  306.                {
  307.                     wsprintf(buf, "phoneNegotiateExtVersion failed, err=x%lx", lRet);
  308.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  309.                       phoneError(lRet);
  310.                }
  311.  
  312.             //phoneOpen
  313.                //................................................................
  314.                for (i = 0; i < myInfo.dwNumDevices; i++)
  315.                {
  316.                    if ( i == 0)
  317.                        lRet = phoneOpen(myInfo.phoneApp,i,&myPhoneInfo[i].hPhone,
  318.                                  myInfo.dwAPIVersion,0,(DWORD)phoneCallback, PHONEPRIVILEGE_OWNER);
  319.                    else
  320.                        lRet = phoneOpen(myInfo.phoneApp,i,&myPhoneInfo[i].hPhone,
  321.                                  myInfo.dwAPIVersion,0,(DWORD)phoneCallback, PHONEPRIVILEGE_MONITOR);
  322.                    
  323.                    if (lRet == 0)
  324.                    {
  325.                      wsprintf(buf, "phoneOpen succeeded!");
  326.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  327.                   pPhoneCaps = (PHONECAPS *) calloc (1, sizeof(PHONECAPS)+1000);
  328.                       pPhoneCaps->dwTotalSize = sizeof(PHONECAPS) + 1000;
  329.                          
  330.                       phoneGetDevCaps(myInfo.phoneApp,i,
  331.                       myInfo.dwAPIVersion, myInfo.dwExtVersion, pPhoneCaps);
  332.                       strcpy(buf, ((LPSTR)(pPhoneCaps)+pPhoneCaps->dwProviderInfoOffset));
  333.                   strcat( buf, " is the phone providor's name." );
  334.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  335.                   strcpy(buf, ((LPSTR)(pPhoneCaps)+pPhoneCaps->dwPhoneNameOffset));
  336.                      
  337.                   if (i == 0)
  338.                   {
  339.                      strcat( buf, " is the phone's name opened with OWNER privilege." );
  340.                      SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  341.                   }
  342.                   else
  343.                   {
  344.                      strcat( buf, " is the phone's name opened with MONITOR privilege." );
  345.                      SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  346.                   }
  347.                }
  348.                    else 
  349.                    {
  350.                        wsprintf( buf,"phoneOpen failed, err=x%lx", lRet);
  351.                        phoneError(lRet);
  352.                       break;
  353.                }
  354.                   } 
  355.  
  356.             break;
  357.       
  358.       case WM_SIZE:
  359.           MoveWindow(hListWnd,0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
  360.          break;
  361.  
  362.       case WM_DESTROY :
  363.          PostQuitMessage(0);
  364.          break;
  365.             
  366.       default :
  367.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  368.    }
  369.  
  370.    return( 0L );
  371. }
  372.  
  373.  
  374.  
  375. /****************************************************************************
  376.     FUNCTION: phoneCallback
  377.     PURPOSE:  callback function handles phone events
  378. ****************************************************************************/
  379. LRESULT CALLBACK phoneCallback (DWORD  dwDevice, DWORD dwMsg,
  380.                                 DWORD dwCallbackInst, DWORD dwParam1,
  381.                                 DWORD dwParam2,DWORD dwParam3)
  382. {
  383.     
  384.     switch (dwMsg)
  385.     {
  386.         case PHONE_REPLY:
  387.             if (dwParam1 == myPhoneInfo[OWNER].dwRequestID) 
  388.                    if (dwParam2 != 0)
  389.                 {
  390.                        wsprintf( buf,"Function failed, err=x%lx", lRet);
  391.                        phoneError(lRet);
  392.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  393.                    }
  394.             break;       
  395.  
  396.         case PHONE_STATE:
  397.         
  398.             if (dwParam1 == PHONESTATE_RINGMODE)
  399.             {
  400.                 lRet = phoneGetRing(myPhoneInfo[OWNER].hPhone, &dwRingMode, &dwRingVolume);
  401.                 if (lRet == 0)
  402.                {
  403.                 wsprintf(buf, "phoneGetRing succeeded!");
  404.                    SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  405.                if (dwRingMode == 0)
  406.                     {
  407.                         wsprintf(buf, "The phone device is currently not ringing.");
  408.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  409.                }
  410.                     else
  411.                     {
  412.                         wsprintf(buf, "The phone is ringing with a Ring Mode pattern of x%lx", dwRingMode);
  413.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  414.                    wsprintf(buf, "The phnes's Ring Volume is x%lx", dwRingVolume);
  415.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  416.                     }
  417.                }
  418.                  else 
  419.                {
  420.                     wsprintf( buf,"phoneGetRing failed, err=x%lx", lRet);
  421.                    phoneError(lRet);
  422.                }        
  423.               
  424.               break;
  425.               }
  426.             
  427.  
  428.             if (dwParam1 == PHONESTATE_SPEAKERHOOKSWITCH)
  429.             {   
  430.                 lRet = phoneGetHookSwitch(myPhoneInfo[OWNER].hPhone, &dwHookSwitchDevs);
  431.                 if (lRet == 0)
  432.                {
  433.                wsprintf(buf, "phoneGetHookSwitch succeeded!");
  434.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  435.                
  436.                if (dwHookSwitchDevs & PHONEHOOKSWITCHDEV_SPEAKER)
  437.                     {
  438.                         wsprintf(buf, "The phone's HookSwitch Speaker is offhook!");
  439.                        SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  440.                     }
  441.                     else
  442.                     {
  443.                    wsprintf(buf, "The phone's HookSwitch Speaker is onhook!");
  444.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  445.                     }
  446.  
  447.               }
  448.                  else 
  449.                {
  450.                       wsprintf( buf,"phoneGetHookSwitch failed, err=x%lx", lRet);
  451.                    phoneError(lRet);
  452.                }    
  453.             break;                
  454.             }
  455.  
  456.             if (dwParam1 == PHONESTATE_SPEAKERVOLUME)
  457.             {   
  458.                 lRet = phoneGetVolume(myPhoneInfo[OWNER].hPhone, PHONEHOOKSWITCHDEV_SPEAKER, &dwHookSwitchVolume);
  459.                if (lRet == 0)
  460.                {
  461.                 wsprintf(buf, "phoneGetVolume succeeded!");
  462.                    SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  463.                wsprintf(buf, "The current volume for the Speaker Hookswitch is x%lx", dwHookSwitchVolume);
  464.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  465.                }
  466.                  else 
  467.                {
  468.                     wsprintf( buf,"phoneGetVolume failed, err=x%lx", lRet);
  469.                    phoneError(lRet);
  470.                }    
  471.             break;                
  472.             }
  473.  
  474.             if (dwParam1 == PHONESTATE_SPEAKERGAIN)
  475.             {   
  476.                 lRet = phoneGetGain(myPhoneInfo[OWNER].hPhone, PHONEHOOKSWITCHDEV_SPEAKER, &dwGain);
  477.                 if (lRet == 0)
  478.                {
  479.                   wsprintf(buf, "phoneGetGain succeeded!");
  480.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  481.                     wsprintf(buf, "The current Gain is x%lx", dwGain);
  482.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  483.                }
  484.                  else 
  485.                {
  486.                       wsprintf( buf,"phoneGetGain failed, err=x%lx", lRet);
  487.                     phoneError(lRet);
  488.                }
  489.             break;                
  490.             }
  491.             
  492.             if (dwParam1 == PHONESTATE_DISPLAY)
  493.             {   
  494.                 pVarString = (VARSTRING *) calloc (1, sizeof(VARSTRING)+1000);
  495.                 pVarString->dwTotalSize = sizeof(VARSTRING) + 1000;
  496.                 lRet = phoneGetDisplay(myPhoneInfo[OWNER].hPhone, pVarString);
  497.                 if (lRet == 0)
  498.                {
  499.                   wsprintf(buf, "phoneGetDisplay succeeded!");
  500.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  501.                strcpy(buf, lpszTitle);
  502.                //strcpy(buf, ((LPSTR)(pVarString)+pVarString->dwStringOffset));
  503.                strcat( buf, " is the current phone display." );
  504.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  505.                }
  506.                  else 
  507.                {
  508.                    wsprintf( buf,"phoneGetDisplay failed, err=x%lx", lRet);
  509.                   phoneError(lRet);
  510.                }    
  511.                     
  512.                 free (pVarString);
  513.                 break;
  514.               }
  515.    }
  516.    return (TRUE);
  517.  
  518.  
  519. /****************************************************************************
  520.     FUNCTION: phoneError
  521.     PURPOSE:  phone error messages
  522. ****************************************************************************/
  523. void phoneError (LONG lrc)
  524. {
  525.  switch (lrc) {
  526.     case PHONEERR_INVALAPPHANDLE:
  527.        MessageBox (hWnd, "Invalid app handle.", "", MB_OK);
  528.        break;
  529.     case PHONEERR_BADDEVICEID:
  530.        MessageBox (hWnd,"The specified phone device ID is out of range.", "", 
  531.                    MB_OK);
  532.        break;
  533.     case PHONEERR_INCOMPATIBLEAPIVERSION:
  534.        MessageBox (hWnd, "Incompatible API version.", "", MB_OK);
  535.        break;
  536.     
  537.     case PHONEERR_INVALBUTTONLAMPID:
  538.        MessageBox (hWnd, "Invalid Button Lamp ID.", "", MB_OK);
  539.        break;
  540.  
  541.     case PHONEERR_INVALBUTTONMODE:
  542.        MessageBox (hWnd, "Invalid Button Mode.", "", MB_OK);
  543.        break;
  544.  
  545.     case PHONEERR_INVALBUTTONSTATE:
  546.        MessageBox (hWnd, "Invalid Button State", "", MB_OK);
  547.        break;
  548.  
  549.     case PHONEERR_INUSE:
  550.        MessageBox (hWnd, "Phone in Use.", "", MB_OK);
  551.        break;
  552.     
  553.     case PHONEERR_INVALHOOKSWITCHDEV:
  554.        MessageBox (hWnd, "Invalid Hookswitch Device.", "", MB_OK);
  555.        break;
  556.  
  557.     case PHONEERR_INVALHOOKSWITCHMODE:
  558.        MessageBox (hWnd, "Invalid Hookswitch Device Mode.", "", MB_OK);
  559.        break;
  560.  
  561.     case PHONEERR_INVALLAMPMODE:
  562.        MessageBox (hWnd, "Invalid Lamp Mode.", "", MB_OK);
  563.        break;
  564.      
  565.     case PHONEERR_INCOMPATIBLEEXTVERSION:
  566.        MessageBox (hWnd, "Incompatible extension version.","", MB_OK);
  567.        break;
  568.     case PHONEERR_NOMEM:
  569.        MessageBox (hWnd, "No memory","", MB_OK);
  570.        break;
  571.     case PHONEERR_NODRIVER:
  572.        MessageBox (hWnd, "No driver loaded", "", MB_OK);
  573.        break;
  574.     case PHONEERR_RESOURCEUNAVAIL:
  575.        MessageBox (hWnd, "Resource overcommittment", "", MB_OK);
  576.        break;
  577.     case PHONEERR_ALLOCATED:
  578.        MessageBox (hWnd, "Allocation error", "", MB_OK);
  579.        break;
  580.     case PHONEERR_INVALDATAID:
  581.        MessageBox (hWnd, "The data ID is out of range.", "", MB_OK);
  582.        break;
  583.     case PHONEERR_INVALDEVICECLASS:
  584.        MessageBox (hWnd, "The device class was invalid.", "", MB_OK);
  585.        break;
  586.     case PHONEERR_INVALPOINTER:
  587.        MessageBox (hWnd, "The specified pointer parameter is invalid.",
  588.                    "", MB_OK);
  589.        break;
  590.     case PHONEERR_OPERATIONFAILED:
  591.        MessageBox (hWnd, "Operation failed.", "", MB_OK);
  592.        break;
  593.     case PHONEERR_INVALPHONEHANDLE:
  594.        MessageBox (hWnd, "Invalid phone handle", "", MB_OK);
  595.        break;
  596.     case PHONEERR_INVALPHONESTATE :
  597.        MessageBox (hWnd, "Invalid call state for this function.", "", MB_OK);
  598.        break;
  599.     case PHONEERR_INVALPRIVILEGE:
  600.        MessageBox (hWnd, "Invalid privilege for this function.", "", MB_OK);
  601.        break;
  602.     case PHONEERR_NODEVICE:
  603.        MessageBox (hWnd, "No associated device for given class",
  604.                    "", MB_OK);
  605.        break;
  606.     case PHONEERR_OPERATIONUNAVAIL:
  607.        MessageBox (hWnd, "The operation is unavailable",
  608.                    "", MB_OK);
  609.        break;
  610.     case PHONEERR_INVALPARAM:
  611.         MessageBox(hWnd, "Invalid Paramater", "", MB_OK);
  612.        break; 
  613.  
  614.     case PHONEERR_INVALRINGMODE:
  615.             MessageBox(hWnd, "Invalid Ring Mode", "", MB_OK);
  616.        break; 
  617.  
  618.     }
  619.     
  620.              
  621. }
  622.  
  623. LRESULT CALLBACK About( HWND hDlg,           
  624.                         UINT message,        
  625.                         WPARAM wParam,       
  626.                         LPARAM lParam)
  627. {
  628.    switch (message) 
  629.    {
  630.        case WM_INITDIALOG: 
  631.                return (TRUE);
  632.  
  633.        case WM_COMMAND:                              
  634.                if (   LOWORD(wParam) == IDOK         
  635.                    || LOWORD(wParam) == IDCANCEL)    
  636.                {
  637.                        EndDialog(hDlg, TRUE);        
  638.                        return (TRUE);
  639.                }
  640.                break;
  641.    }
  642.  
  643.    return (FALSE); 
  644. }
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.